//
//  ZYXCourseDetVC.m
//  RuiBeiKang
//
//  Created by iOS开发1 on 2019/1/11.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXCourseDetVC.h"

#import "ZYXCourseOneCell.h"
#import "ZYXCourseDetModel.h"
@interface ZYXCourseDetVC ()
@property (strong,nonatomic)ZYXCourseDetModel *model;
@end

@implementation ZYXCourseDetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

}
-(void)setupViews{
//        self.scroView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationBar_Height-290);
//        [self.view addSubview:self.scroView];
//
//        ZYXCoureDetHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"ZYXCoureDetHeaderView" owner:nil options:nil] lastObject];
//        [self.scroView addSubview:headerView];
//
//        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
//            self.scroView.top = 0;
//             self.scroView.left = 0;
//             self.scroView.right = 0;
//            headerView.height = HEIGHT(400);
//
//        }];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ZYXCourseOneCell" bundle:nil] forCellReuseIdentifier:@"ZYXCourseOneCell"];
    self.tableView.separatorStyle  = UITableViewCellSeparatorStyleNone;
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationBar_Height-290-HomeIndicator_Height);
    self.tableView.estimatedRowHeight = HEIGHT(150);
    [self.view addSubview:self.tableView];
}
-(void)loadData{
    if ([UID integerValue] ==0) {
        [ZYXLoginViewController setupLogin];
        return;
    }
    NSDictionary *dic = @{@"id":self.zid,@"user_id":UID};
    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_FenleiDetail) parmas:dic successBloock:^(NSDictionary  *responseObject) {
        NSLog(@"responseObject =%@",responseObject);
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            self.model = [ZYXCourseDetModel mj_objectWithKeyValues:responseObject[@"data"]];
            [self.tableView reloadData];
        }
        
    } failureBlock:^(NSError *error) {
        
    }];
    
}
#pragma mark tableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZYXCourseOneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZYXCourseOneCell"];
    cell.model = self.model;
    [cell.collectionBtn addTarget:self action:@selector(clickCollection) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

-(void)clickCollection{
    NSDictionary *dic = @{@"id":self.zid,@"user_id":UID};
    [NetWork POSTWithUrlString:kInterfaceAllUrl(PATH_CollectionCreate) parmas:dic successBloock:^(NSDictionary  *responseObject) {
        NSLog(@"responseObject =%@",responseObject);
       
         if ([responseObject[@"code"] isEqualToNumber:@200]) {
             [self loadData];
              [JKToast showWithText:responseObject[@"message"]];
         }else{
              [JKToast showWithText:responseObject[@"message"]];
         }
    } failureBlock:^(NSError *error) {
        
    }];
}



@end
